﻿using SqlSugar;
using Fortunate.IService;
using Fortunate.Service.BASE;
using Fortunate.Application.Entities;

namespace Fortunate.Service
{
    public class LoginService : BaseServices<Users>, ILoginService
    {
        public LoginService(ISqlSugarClient _db) : base(_db)
        {
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="Account">账号</param>
        /// <param name="Password">密码</param>
        /// <returns></returns>
        public async Task<Users> GetLogin(string Account, string Password)
        {
            return await db.Queryable<Users>().FirstAsync(x => x.Account == Account && x.Password == Password);
        }

        /// <summary>
        /// 手机号码登录
        /// </summary>
        /// <param name="Phone">输入手机号码</param>
        /// <returns></returns>
        public async Task<List<Users>> GetLogin(string Phone)
        {
            return await db.Queryable<Users>().Where(x => x.Phone == Phone).ToListAsync();
        }

        /// <summary>
        /// 根据账号获取密码加盐码
        /// </summary>
        /// <param name="Account">账号</param>
        /// <returns></returns>
        public async Task<string> GetAccountSalt(string Account)
        {
            var UsersList = await db.Queryable<Users>().Where(x => x.Account == Account).ToListAsync();
            if (UsersList.Count == 1)
            {
                return string.Concat("ok", Common.Helper.PasswordHelper.SaltCode, UsersList[0].Salt);
            }
            return "";
        }
    }
}
